// JavaScript Document
/*
这里放的是公共的函数全局定义

*/
//######################弹出确认框#############
//id   弹出的ID
//fun  sure 执行的函数
//obj  触发该函数调用的对象
//msg  弹出框的消息
var RegisFun = "";
var objs = "";
var args1 = ""; //ContactPerson
function delete_confirms() 
{
var box="<div id=\"DeleteBox\" class=\"Popconfirms\"><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
box+="<tr><td align=\"center\"><div class=\"Poptxt\">Are you sure to delete?</div></td> </tr> <tr>  <td align=\"center\">";
box+="<span id=\"sureMeg\" class=\"clsWarningMeg\"></span><div class=\"clear20\"></div><table><tr><td><ul class=\"uibtn\">";
box+="<li onclick=\"SureDelete()\" ><span>Sure</span></li></ul></td><td width=\"10\"></td><td><ul class=\"uibtn\"><li ";
box += "onclick=\"CloseDelete()\"><span>Quit</span></li></ul></td></tr></table></td></tr></table></div>";
//var ts = document.getElementById("DeleteBox");
//if (ts == undefined)
// document.body.innerHTML = document.body.innerHTML + box;


var id  = arguments[0];
var fun = arguments[1];
var obj = arguments[2];
var msg = arguments[4]; 

var argstr = [];
argstr = id.split('_');

if (argstr[1] != null)
args1 = argstr[1];

idbox = argstr[0];
$("#" + idbox).PopupDiv({
PopupDivId: "PopupDiv" + id,
title: "",
modal: true,
top: document.documentElement.scrollTop + 200
});
RegisFun = fun;
objs = obj;

}
function SureDelete() {
    //deal the function
    if (RegisFun != "" && RegisFun != null)
        eval(RegisFun + "()");
    //hidden the popdiv  
    CloseDelete();
}

function CloseDelete()
 {  
    $("#DeleteBox").PopupDiv("remove"); 

}
// ################确认框完毕############


function ToggleDocument(id)
{
	$("#"+id).toggle();
}
function CloseDocument(id)
{
	$("#"+id).hide();
}

//添加邮件地址
function addModel(type)
{
var str1,str2,str3,str,msg,id;
msg = "最多只能放5个";
msg2 = "最多只能放2个";
//电话
str1 = " <div class=\"activityWrap\"><table width=\"285\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"activity-phnone\">";
str1 = str1+"<tr><td colspan=\"3\"><p class=\"upinput\"><select class=\"autoselect\"><option>General</option><option>Direct </option>";
str1 = str1 + "<option>Moblie </option><option>Direct </option><option>Skype </option></select><img class=\"addimg\" src=\"Media/Css/images/add-green.png\"";
str1 = str1 + "onClick=\'addModel(\"p\")\'/><img  src=\"Media/Css/images/delete-green.png\"  onClick=\'delModel(this)\' ></p></td>";
str1 = str1 + "</tr><tr><td width=\"70\"><input type=\"text\" class=\"input60\" ></td>";
str1 = str1 + "<td width=\"70\"><input type=\"text\" class=\"input60\"></td><td><input type=\"text\" class=\"input100\" ></td>";
str1 = str1 + "</tr><tr><td class=\"checkbox-wrap\"><input type=\"checkbox\" ><label>DNC</label></td>";
str1 = str1 + "<td class=\"checkbox-wrap\" colspan=\"2\"><input type=\"checkbox\" ><label>Unsubscribe</label></td></tr></table></div>";



//传真
str2 = "<div class=\"activityWrap\"><table width=\"285\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"activity-phnone\">";
str2 = str2 +"<tr><td colspan=\"3\"><p class=\"upinput\"><select class=\"autoselect\"><option>General</option><option>Direct </option>";
str2 = str2 + "<option>Moblie </option><option>Direct </option><option>Skype </option></select><img class=\"addimg\" src=\"Media/Css/images/add-green.png\"";
str2 = str2 + "onClick=\'addModel(\"f\")\'/><img  src=\"Media/Css/images/delete-green.png\"   onClick=\'delModel(this)\' >";
str2 = str2 +"</p></td></tr><tr><td width=\"70\"><input type=\"text\" class=\"input60\" ></td>";
str2 = str2 +"<td width=\"70\"><input type=\"text\" class=\"input60\"></td><td><input type=\"text\" class=\"input100\" ></td>";
str2 = str2 +"</tr><tr><td class=\"checkbox-wrap\"><input type=\"checkbox\" ><label>DNC</label></td>";
str2 = str2 +"<td class=\"checkbox-wrap\" colspan=\"2\"><input type=\"checkbox\" ><label>Unsubscribe</label></td></tr></table></div>";




//邮件
str3 = "<div class=\"activityWrap\"><table width=\"285\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"activity-phnone\"><tr><td >";
str3 = str3 + "<p class=\"upinput\"><select class=\"autoselect\"><option>Facebook</option><option>MSN</option></select><img  src=\"Media/Css/images/add-green.png\" class=\"addimg\"  onClick=\'addModel(\"e\")\' alt=\"\" />";
str3 = str3 +"<img  src=\"Media/Css/images/delete-green.png\"  onClick=\"delModel(this)\"/></p>";
str3 = str3 +"</td></tr><tr><td ><input type=\"text\" class=\"input200\" ></td></tr><tr><td class=\"checkbox-wrap\" ><input type=\"checkbox\" >";
str3 = str3 +"<label>Unsubscribe</label></td></tr> </table></div>";


//站点
str4 = "<div class=\"activityWrap\" style=\"height:49px\"><p class=\"upinput\">Website <img  src=\"Media/Css/images/delete-green.png\"  onClick=\"delModel(this)\"/></p><input type=\"text\" class=\"input200\" /></div>";


 id="";
 switch(type)
 {
  case "p" :
  str=str1;
  id="phone-wrap";
  break;
  case "f" :
  id="fax-wrap";
  str=str2;
  break;
  case "e" :
  id="email-wrap";
  str=str3;
  break;

case "w":
    id = "websitwrap";
    str = str4;
    break;

  default :
  break;
}


var len = $("#" + id).find(".activity-phnone").size();
if (type != "w") {
    if (len < 5) {
          $("#" + id).append(str);
           if(len<4)
            $("#" + id).find(".addimg").show();
            else
            $("#" + id).find(".addimg").hide();
    }
    else {
        $("#" + id).find(".addimg").hide();
        alert(msg)
    }
} else if (type == "w"){
    if (len < 1)
        $("#" + id).append(str);
    else
        alert(msg2)
}
}

function addModelWebsit(type) {

    str4 = "<div class=\"activityWrap\" style=\"height:59px\"><p class=\"upinput\"><select class=\"autoselect\" ><option>Official Website</option><option>Blog</option></select><img  src=\"Media/Css/images/delete-green.png\"  onClick=\"delModel(this)\"/></p><input type=\"text\" class=\"input200\" /></div>";

   var   id = "";
    switch (type) {
        case "w":
            id = "websitwrap";
            str = str4;
            break;
        default:
            break;
    }

    msg2 = "最多只能放2个";
    var len = $("#" + id).find(".activityWrap").size();
    if (type == "w") {
        if (len < 1)
            $("#" + id).append(str);
        else
            alert(msg2)
    }

}




//删除
function delModel(id)
{
    $(id).parents(".parnt").find(".addimg").show();  
    $(id).parents(".activityWrap").remove();

}


/* confirm  pop*/
//disp_confirm
function undo_disp_confirms(id)
   {

	   $("#"+id).PopupDiv({	   
				PopupDivId: "PopupDiv"+id,
				title: "",
				modal: true,
				//left: document.documentElement.scrollLeft + 500,
				top: document.documentElement.scrollTop + 200
			});

}

function delete_disp_confirms(id)
{
    $("#" + id).PopupDiv({
        PopupDivId: "PopupDiv" + id,
        title: "",
        modal: true,
        //left: document.documentElement.scrollLeft + 500,
        top: document.documentElement.scrollTop + 200
    });


}
// for tab

function checkTab(tbselect)
 {
     $("#" + tbselect).attr("class", "selected");     
}